from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-22 14:09:57.299549
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 22, Sep, 2022
Time: 14:10:04
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.4862
Nobs: 787.000 HQIC: -50.8148
Log likelihood: 10116.1 FPE: 6.95455e-23
AIC: -51.0201 Det(Omega_mle): 6.20750e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298969 0.053857 5.551 0.000
L1.Burgenland 0.108479 0.035865 3.025 0.002
L1.Kärnten -0.106515 0.019074 -5.584 0.000
L1.Niederösterreich 0.207501 0.074981 2.767 0.006
L1.Oberösterreich 0.105498 0.072157 1.462 0.144
L1.Salzburg 0.252407 0.038287 6.593 0.000
L1.Steiermark 0.038085 0.050036 0.761 0.447
L1.Tirol 0.106099 0.040555 2.616 0.009
L1.Vorarlberg -0.059264 0.034898 -1.698 0.089
L1.Wien 0.053111 0.064496 0.823 0.410
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060788 0.111710 0.544 0.586
L1.Burgenland -0.033951 0.074392 -0.456 0.648
L1.Kärnten 0.048016 0.039563 1.214 0.225
L1.Niederösterreich -0.173832 0.155525 -1.118 0.264
L1.Oberösterreich 0.388885 0.149669 2.598 0.009
L1.Salzburg 0.287397 0.079414 3.619 0.000
L1.Steiermark 0.107359 0.103785 1.034 0.301
L1.Tirol 0.312750 0.084120 3.718 0.000
L1.Vorarlberg 0.026619 0.072385 0.368 0.713
L1.Wien -0.017214 0.133777 -0.129 0.898
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191440 0.027659 6.921 0.000
L1.Burgenland 0.089737 0.018419 4.872 0.000
L1.Kärnten -0.008303 0.009796 -0.848 0.397
L1.Niederösterreich 0.263153 0.038507 6.834 0.000
L1.Oberösterreich 0.127965 0.037057 3.453 0.001
L1.Salzburg 0.047040 0.019663 2.392 0.017
L1.Steiermark 0.018290 0.025697 0.712 0.477
L1.Tirol 0.093438 0.020828 4.486 0.000
L1.Vorarlberg 0.059045 0.017922 3.295 0.001
L1.Wien 0.119179 0.033123 3.598 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109189 0.028321 3.855 0.000
L1.Burgenland 0.044463 0.018860 2.358 0.018
L1.Kärnten -0.015773 0.010030 -1.573 0.116
L1.Niederösterreich 0.192958 0.039429 4.894 0.000
L1.Oberösterreich 0.293067 0.037945 7.724 0.000
L1.Salzburg 0.114170 0.020133 5.671 0.000
L1.Steiermark 0.101851 0.026312 3.871 0.000
L1.Tirol 0.115063 0.021326 5.395 0.000
L1.Vorarlberg 0.071173 0.018351 3.878 0.000
L1.Wien -0.026475 0.033916 -0.781 0.435
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132567 0.051289 2.585 0.010
L1.Burgenland -0.052266 0.034155 -1.530 0.126
L1.Kärnten -0.040087 0.018164 -2.207 0.027
L1.Niederösterreich 0.172180 0.071406 2.411 0.016
L1.Oberösterreich 0.134841 0.068717 1.962 0.050
L1.Salzburg 0.285657 0.036461 7.835 0.000
L1.Steiermark 0.036372 0.047650 0.763 0.445
L1.Tirol 0.163186 0.038622 4.225 0.000
L1.Vorarlberg 0.102376 0.033234 3.080 0.002
L1.Wien 0.067267 0.061420 1.095 0.273
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058689 0.040734 1.441 0.150
L1.Burgenland 0.038386 0.027126 1.415 0.157
L1.Kärnten 0.051086 0.014426 3.541 0.000
L1.Niederösterreich 0.222704 0.056711 3.927 0.000
L1.Oberösterreich 0.284605 0.054575 5.215 0.000
L1.Salzburg 0.049245 0.028958 1.701 0.089
L1.Steiermark -0.004557 0.037844 -0.120 0.904
L1.Tirol 0.148235 0.030674 4.833 0.000
L1.Vorarlberg 0.072910 0.026394 2.762 0.006
L1.Wien 0.079689 0.048780 1.634 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181056 0.048698 3.718 0.000
L1.Burgenland -0.006415 0.032430 -0.198 0.843
L1.Kärnten -0.061073 0.017247 -3.541 0.000
L1.Niederösterreich -0.082478 0.067798 -1.217 0.224
L1.Oberösterreich 0.192369 0.065245 2.948 0.003
L1.Salzburg 0.056767 0.034619 1.640 0.101
L1.Steiermark 0.232137 0.045243 5.131 0.000
L1.Tirol 0.493487 0.036671 13.457 0.000
L1.Vorarlberg 0.048200 0.031555 1.528 0.127
L1.Wien -0.051802 0.058318 -0.888 0.374
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165207 0.055909 2.955 0.003
L1.Burgenland -0.010807 0.037232 -0.290 0.772
L1.Kärnten 0.066591 0.019801 3.363 0.001
L1.Niederösterreich 0.200510 0.077837 2.576 0.010
L1.Oberösterreich -0.065449 0.074907 -0.874 0.382
L1.Salzburg 0.212968 0.039745 5.358 0.000
L1.Steiermark 0.116746 0.051943 2.248 0.025
L1.Tirol 0.074663 0.042101 1.773 0.076
L1.Vorarlberg 0.123554 0.036227 3.411 0.001
L1.Wien 0.117978 0.066953 1.762 0.078
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359190 0.032387 11.091 0.000
L1.Burgenland 0.006373 0.021567 0.295 0.768
L1.Kärnten -0.023174 0.011470 -2.020 0.043
L1.Niederösterreich 0.219839 0.045089 4.876 0.000
L1.Oberösterreich 0.179796 0.043392 4.144 0.000
L1.Salzburg 0.045463 0.023024 1.975 0.048
L1.Steiermark -0.016428 0.030089 -0.546 0.585
L1.Tirol 0.106455 0.024388 4.365 0.000
L1.Vorarlberg 0.073170 0.020986 3.487 0.000
L1.Wien 0.050401 0.038784 1.300 0.194
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040919 0.150713 0.191714 0.156324 0.125326 0.112151 0.066477 0.223171
Kärnten 0.040919 1.000000 -0.002907 0.129495 0.041853 0.095468 0.430430 -0.053325 0.101463
Niederösterreich 0.150713 -0.002907 1.000000 0.336289 0.152197 0.300152 0.107899 0.183036 0.324152
Oberösterreich 0.191714 0.129495 0.336289 1.000000 0.230444 0.332301 0.171659 0.170394 0.262579
Salzburg 0.156324 0.041853 0.152197 0.230444 1.000000 0.146861 0.123561 0.147739 0.133091
Steiermark 0.125326 0.095468 0.300152 0.332301 0.146861 1.000000 0.153002 0.140111 0.078917
Tirol 0.112151 0.430430 0.107899 0.171659 0.123561 0.153002 1.000000 0.114247 0.152685
Vorarlberg 0.066477 -0.053325 0.183036 0.170394 0.147739 0.140111 0.114247 1.000000 0.004227
Wien 0.223171 0.101463 0.324152 0.262579 0.133091 0.078917 0.152685 0.004227 1.000000